package cc.lison.aboutme;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    LinearLayout ll_dial;
    TextView tv_mobile, tv_from;
    ImageView iv_git;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();
    }

    void initView() {
        getSupportActionBar().hide();
        ll_dial = findViewById(R.id.ll_dial);
        tv_mobile = findViewById(R.id.tv_mobile);
        iv_git = findViewById(R.id.iv_git);
        tv_from = findViewById(R.id.tv_from);

        ll_dial.setOnClickListener(this);
        iv_git.setOnClickListener(this);
    }

    void initData() {
        String statement = "1. 这个APP灵感来源自@Damodar Lohani的项目flutter_ui_challenges。";
        SpannableString sstr = new SpannableString(statement);
        Resources resources = getResources();
        ForegroundColorSpan span = new ForegroundColorSpan(resources.getColor(R.color.md_deep_purple_600));
        ForegroundColorSpan span1 = new ForegroundColorSpan(resources.getColor(R.color.md_deep_purple_600));
        sstr.setSpan(span, 13, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sstr.setSpan(span1, 31, statement.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        tv_from.setText(sstr);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_dial:
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tv_mobile.getText()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            case R.id.iv_git:
                Uri uri = Uri.parse("https://gitee.com/lison/Aboutme");
                Intent intent_git = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent_git);
                break;
        }
    }
}
